package com.demo.apparel.controller.web;

import com.demo.apparel.common.Result;
import com.demo.apparel.dto.PlatformVisitDTO;
import com.demo.apparel.entity.VisitCountDaily;
import com.demo.apparel.service.uniapp.PlatformVisitService;
import com.demo.apparel.service.uniapp.VisitCountService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/web/visit")
@Tag(name = "访问统计模块", description = "记录并查询访问量")
public class WebVisitCountController {

    @Autowired
    private VisitCountService visitCountService;

    @Autowired
    private PlatformVisitService platformVisitService;
    @GetMapping("/count")
    @Operation(summary = "获取总的访问量miniapp作为uri的标识")
    public Result<Long> getVisitCount(@RequestParam String uri) {
        long count = visitCountService.getVisitCount(uri);
        return Result.success(count);
    }

    /**
     *
     * @return
     */
    @GetMapping("/today")
    @Operation(summary = "获取每天的访问量")
    public Result<List<VisitCountDaily>> getTodayVisits() {
        List<VisitCountDaily> visits = visitCountService.getVisitsByToday();
        return Result.success(visits);
    }


    @GetMapping("/todayNum")
    @Operation(summary = "获取每天的访问量并且是每个平台的详细")
    public Result<List<PlatformVisitDTO>> getTodayVisit() {
        return Result.success(platformVisitService.getTodayVisit());
    }

    @GetMapping("/total")
    @Operation(summary = "获取全部的访问量并且包含每个平台的访问量")
    public Result<List<PlatformVisitDTO>> getTotalVisit() {
        return Result.success(platformVisitService.getTotalVisit());
    }

}
